home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / -archivi / -recent2 / amhelios.lha / AmHelios / p_render.h < prev    next >
C/C++ Source or Header  |  1997-07-13  |  10KB  |  256 lines

  1. ////////////////////////////////////////////////////////////
  2. //
  3. //  P_RENDER.H - Polygon Renderer Class Include File
  4. //
  5. //  Version:    1.03A
  6. //
  7. //  History:    94/08/23 - Version 1.00A release.
  8. //              94/10/12 - Modified PolyRender constructor
  9. //                         to initialize intensity and clear
  10. //                         intensity_flag.
  11. //                       - Added intensity and
  12. //                         intensity_flag data members.
  13. //                       - Added IntensityFlag,
  14. //                         GetIntensity, DisableIntensity,
  15. //                         EnableIntensity and SetIntensity
  16. //                         functions.
  17. //              94/10/14 - Modified PolyRender constructor
  18. //                         to initialize contrast and clear
  19. //                         contrast_flag.
  20. //                       - Added contrast and contrast_flag
  21. //                         data members.
  22. //                       - Added ContrastFlag, GetContrast,
  23. //                         DisableContrast, EnableContrast
  24. //                         and SetContrast functions.
  25. //              94/11/26 - Added color_scale and
  26. //                         intensity_adj data members.
  27. //                       - Added CalcColorScale function.
  28. //                       - Modified Open function prototype.
  29. //                       - Added P_MaxColorBand definition.
  30. //              94/12/16 - Version 1.01A release.
  31. //              95/02/05 - Version 1.02A release.
  32. //              95/03/21 - Modified Render and GetVertexInfo
  33. //                         function prototypes.
  34. //              95/03/22 - Modified CalcColorScale function
  35. //                         to prevent divide-by-zero error.
  36. //                       - Added Reset function prototype.
  37. //              95/03/25 - Removed "c_jitter.h" and
  38. //                         "gamma.h" include directives.
  39. //                       - Deleted "jitter_flag" and
  40. //                         "gamma_flag" data members.
  41. //                       - Deleted "gamma" and "jitter"
  42. //                         members.
  43. //                       - Removed "gamma_flag" and
  44. //                         "jitter_flag" initialization from
  45. //                         PolyRender constructor.
  46. //                       - Removed DisableGamma,
  47. //                         DisableJitter, EnableGamma,
  48. //                         EnableJitter, GammaFlag,
  49. //                         GetGamma, GetNoiseLevel,
  50. //                         GetStatus, JitterFlag, SetGamma
  51. //                         and SetNoiseLevel functions.
  52. //              95/06/05 - Changed PolyRender data member
  53. //                         z_buffer from float to long.
  54. //                       - Changed ScanInfo data member x
  55. //                         from double to int data type.
  56. //                       - Changed ScanInfo data member z
  57. //                         from double to long data type.
  58. //                       - Changed ScanInfo data member
  59. //                         color from Spectra to IntRGB
  60. //                         data type.
  61. //                       - Changed PR_Infinity from float
  62. //                         to long data type.
  63. //                       - Added ScaleZ function.
  64. //                       - Added DDA_Info structure.
  65. //                       - Added pi, si, r, inc, and dec
  66. //                         data members.
  67. //                       - Added LongFloorDiv and
  68. //                         IntFloorDiv functions.
  69. //                       - Added EdgeSetup, EdgeScan,
  70. //                         SpanSetup and SpanScan function
  71. //                         prototypes.
  72. //              95/06/17 - Deleted color_type data member
  73. //                         from PolyRender.
  74. //                       - Removed color_type initialization
  75. //                         from PolyRender constructor.
  76. //                       - Deleted GetColorType and
  77. //                         SetColorType functions.
  78. //                       - Deleted PR_RGB, PR_MONO and
  79. //                         PR_PSEUDO defintions.
  80. //              95/07/05 - Added ss_rate, ss_ymax and
  81. //                         ss_ymin data members to
  82. //                         PolyRender class.
  83. //                       - Added ss_screen data member to
  84. //                         VertexInfo class.
  85. //                       - Modified Render function
  86. //                         prototype.
  87. //              95/07/21 - Version 1.02B release.
  88. //              96/02/14 - Version 1.02C release.
  89. //              96/04/01 - Version 1.03A release.
  90. //
  91. //  Compilers:  Microsoft Visual C/C++ Professional V1.5
  92. //              Borland C++ Version 4.5
  93. //
  94. //  Author:     Ian Ashdown, P.Eng.
  95. //              byHeart Software Limited
  96. //              620 Ballantree Road
  97. //              West Vancouver, B.C.
  98. //              Canada V7S 1W3
  99. //              Tel. (604) 922-6148
  100. //              Fax. (604) 987-7621
  101. //
  102. //  Copyright 1994-1996 byHeart Software Limited
  103. //
  104. //  The following source code has been derived from:
  105. //
  106. //    Ashdown, I. 1994. Radiosity: A Programmer's
  107. //    Perspective. New York, NY: John Wiley & Sons.
  108. //
  109. //  It may be freely copied, redistributed, and/or modified
  110. //  for personal use ONLY, as long as the copyright notice
  111. //  is included with all source code files.
  112. //
  113. ////////////////////////////////////////////////////////////
  114.  
  115. #ifndef _P_RENDER_H
  116. #define _P_RENDER_H
  117.  
  118. #include <limits.h>
  119. #include "out_poly.h"
  120. #include "bitmap24.h"
  121.  
  122.  
  123. // Maximum reflected color band value
  124. static const double P_MaxColorBand = ((double) 254 /
  125.     (double) 255);
  126.  
  127. // Maximum Z-buffer value
  128. static const long PR_Infinity = LONG_MAX;
  129.  
  130. struct DDA_Info     // Edge/span DDA info
  131. {
  132.   int x;            // x-axis value (edge only)
  133.   long z;           // z-axis value
  134.   IntRGB color;     // RGB color values
  135. };
  136.  
  137. struct VertexInfo       // Vertex information
  138. {
  139.   POINT ss_screen;      // Supersampling screen co-ords
  140.   POINT screen;         // Integer screen co-ordinates
  141.   Point3 posn;          // Scaled position
  142.   Spectra color;        // Spectral radiant exitance
  143. };
  144.  
  145. struct ScanInfo         // Scan line intersection info
  146. {
  147.   int x;                // X-axis co-ordinate
  148.   long z;               // Pseudodepth
  149.   IntRGB color;         // RGB color
  150. };
  151.  
  152. struct EdgeInfo         // Edge information
  153. {
  154.   BOOL first;           // First intersection flag
  155.   ScanInfo isect[2];    // Scan line intersection array
  156. };
  157.  
  158. class PolyRender        // Polygon renderer
  159. {
  160.   private:
  161.     BOOL contrast_flag;         // Contrast flag
  162.     BOOL intensity_flag;        // Intensity flag
  163.     int ymin;                   // Minimum y-axis co-ord
  164.     int ymax;                   // Maximum y-axis co-ord
  165.     int ss_ymin;                // Min supersampling co-ord
  166.     int ss_ymax;                // Max supersampling co-ord
  167.     int width;                  // Display width
  168.     int height;                 // Display height
  169.     int num_vert;               // Number of vertices
  170.     int ss_rate;                // Supersampling rate
  171.     double contrast;            // Contrast scaling factor
  172.     double intensity;           // Intensity scaling factor
  173.     double color_scale;         // Color scaling factor
  174.     long **z_buffer;            // Depth buffer pointer
  175.     EdgeInfo *edge_list;        // Edge list pointer
  176.     DDA_Info pi;                // DDA pixel parameters
  177.     DDA_Info si;                // DDA delta values
  178.     DDA_Info r;                 // DDA offset error terms
  179.     DDA_Info inc;               // DDA increment values
  180.     DDA_Info dec;               // DDA decrement values
  181.     Spectra intensity_adj;      // Intensity adjustment
  182.     VertexInfo v_info[8];       // Vertex info table
  183.     WinBitmap *pbmap;           // Bitmap object pointer
  184.  
  185.     // Calculate integer floor(a / b) - assumes b > 0
  186.     int IntFloorDiv( int a, int b )
  187.     {
  188.       if (a >= 0)
  189.         return a / b;
  190.       else
  191.         return (a / b) + ((a % b) == 0 ? 0 : - 1);
  192.     }
  193.  
  194.     // Calculate long floor(a / b) - assumes b > 0
  195.     long LongFloorDiv( long a, long b )
  196.     {
  197.       if (a >= 0)
  198.         return a / b;
  199.       else
  200.         return (a / b) + ((a % b) == 0 ? 0 : - 1);
  201.     }
  202.  
  203.     // Scale z-axis value from float to long (assumes
  204.     // range is 0.0 to 1.0)
  205.     long ScaleZ( double x )
  206.     { return ((long) (x * (double) LONG_MAX)); }
  207.  
  208.     void EdgeSetup( VertexInfo *, VertexInfo * );
  209.     void EdgeScan( VertexInfo *, VertexInfo * );
  210.     void GetVertexInfo( OutPolygon &, double, double );
  211.     void ScanEdges();
  212.     void DrawEdgeList();
  213.     void SpanSetup( ScanInfo *, ScanInfo * );
  214.     void SpanScan( ScanInfo *, ScanInfo *, int );
  215.  
  216.   public:
  217.     PolyRender()
  218.     {
  219.       contrast_flag = FALSE;
  220.       intensity_flag = FALSE;
  221.       contrast = 1.0;
  222.       intensity = 0.0;
  223.     }
  224.  
  225.     BOOL ContrastFlag() { return contrast_flag; }
  226.     BOOL IntensityFlag() { return intensity_flag; }
  227.     BOOL Open( WinBitmap *, double );
  228.     double GetContrast() { return contrast; }
  229.     double GetIntensity() { return intensity; }
  230.     void CalcColorScale( double rmax )
  231.     {
  232.       if (rmax > MIN_VALUE)
  233.         color_scale = P_MaxColorBand / rmax;
  234.       else
  235.         color_scale = 1.0;
  236.     }
  237.     void Close();
  238.     void DisableContrast() { contrast_flag = FALSE; }
  239.     void DisableIntensity() { intensity_flag = FALSE; }
  240.     void EnableContrast() { contrast_flag = TRUE; }
  241.     void EnableIntensity() { intensity_flag = TRUE; }
  242.     void Render( OutPolygon &, int, double, double );
  243.     void Reset();
  244.     void SetContrast( double c ) { contrast = c; }
  245.     void SetIntensity( double i )
  246.     {
  247.       intensity = i;
  248.       intensity_adj.SetRedBand((float) i);
  249.       intensity_adj.SetGreenBand((float) i);
  250.       intensity_adj.SetBlueBand((float) i);
  251.     }
  252. };
  253.  
  254. #endif
  255.  
  256.